package aip.assignment2.persistence.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Stone
 */
@Entity
@Table(name = "address")
@XmlRootElement
@NamedQueries(
{
	@NamedQuery(name = "Address.findAll", query = "SELECT a FROM Address a"),
	@NamedQuery(name = "Address.findById", query = "SELECT a FROM Address a WHERE a.id = :id"),
	@NamedQuery(name = "Address.findByNumber", query = "SELECT a FROM Address a WHERE a.number = :number"),
	@NamedQuery(name = "Address.findByStreet", query = "SELECT a FROM Address a WHERE a.street = :street"),
	@NamedQuery(name = "Address.findBySuburb", query = "SELECT a FROM Address a WHERE a.suburb = :suburb"),
	@NamedQuery(name = "Address.findByState", query = "SELECT a FROM Address a WHERE a.state = :state"),
	@NamedQuery(name = "Address.findByPostcode", query = "SELECT a FROM Address a WHERE a.postcode = :postcode")
})
public class Address implements Serializable
{
	private static final long serialVersionUID = 1L;
	@Id
	@SequenceGenerator(name = "address_id", allocationSize = 1, sequenceName = "address_id_seq")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "address_id")
	@Basic(optional = false)
	@Column(name = "id")
	private Integer id;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 20)
	@Column(name = "number")
	private String number;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 50)
	@Column(name = "street")
	private String street;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 50)
	@Column(name = "suburb")
	private String suburb;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 50)
	@Column(name = "\"state\"")
	private String state;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 20)
	@Column(name = "postcode")
	private String postcode;
	@JoinColumn(name = "country", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private Country country;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "address")
	private List<Customer> customerList;
	public Address()
	{
	}
	public Address(Integer id)
	{
		this.id = id;
	}
	public Address(Integer id, String number, String street, String suburb, String state, String postcode)
	{
		this.id = id;
		this.number = number;
		this.street = street;
		this.suburb = suburb;
		this.state = state;
		this.postcode = postcode;
	}
	public Integer getId()
	{
		return id;
	}
	public void setId(Integer id)
	{
		this.id = id;
	}
	public String getNumber()
	{
		return number;
	}
	public void setNumber(String number)
	{
		this.number = number;
	}
	public String getStreet()
	{
		return street;
	}
	public void setStreet(String street)
	{
		this.street = street;
	}
	public String getSuburb()
	{
		return suburb;
	}
	public void setSuburb(String suburb)
	{
		this.suburb = suburb;
	}
	public String getState()
	{
		return state;
	}
	public void setState(String state)
	{
		this.state = state;
	}
	public String getPostcode()
	{
		return postcode;
	}
	public void setPostcode(String postcode)
	{
		this.postcode = postcode;
	}
	public Country getCountry()
	{
		return country;
	}
	public void setCountry(Country country)
	{
		this.country = country;
	}
	@XmlTransient
	public List<Customer> getCustomerList()
	{
		return customerList;
	}
	public void setCustomerList(List<Customer> customerList)
	{
		this.customerList = customerList;
	}
	@Override
	public int hashCode()
	{
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}
	@Override
	public boolean equals(Object object)
	{
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof Address))
		{
			return false;
		}
		Address other = (Address) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)))
		{
			return false;
		}
		return true;
	}
	@Override
	public String toString()
	{
		return "aip.assignment2.data.entity.Address[ id=" + id + " ]";
	}
}
